package com.yyk.yiliao.ui.home.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.orhanobut.hawk.Hawk;
import com.orhanobut.logger.Logger;
import com.yyk.yiliao.R;
import com.yyk.yiliao.base.BaseActivity;
import com.yyk.yiliao.bean.YuyYueXinxiInfo;
import com.yyk.yiliao.ui.login.activity.LogIn_Activity;
import com.yyk.yiliao.util.TimeUtil;
import com.yyk.yiliao.util.glide.GlideUtils;
import com.yyk.yiliao.util.rx.ApiService;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 预约信息
 */
public class Reservation_Activity extends BaseActivity {

    @BindView(R.id.mReservationinfo_next)
    Button mReservationinfoNext;
    @BindView(R.id.picture)
    ImageView picture;
    @BindView(R.id.true_name)
    TextView trueName;
    @BindView(R.id.doctorclinic)
    ImageView doctorclinic;
    @BindView(R.id.title)
    TextView tvtitle;
    @BindView(R.id.strong)
    TextView strong;
    @BindView(R.id.address)
    TextView address;
    @BindView(R.id.mAddmember2_one)
    LinearLayout mAddmember2One;
    @BindView(R.id.department_name)
    TextView departmentName;

    @BindView(R.id.time)//年月日星期
            TextView time;
    @BindView(R.id.time2)//上午8:00-12:00
            TextView time2;

    @BindView(R.id.ask_price) //价格
            TextView askPrice;


    private YuyYueXinxiInfo yuyYue_info;
    private String scheduling_id;


    @Override
    public int getLayoutId() {
        return R.layout.activity_reservation;
    }

    @Override
    public void initView() {
        initToolbar();
    }

    private void initToolbar() {
        setBackArrow();
        setTitle("预约信息");
    }

    @Override
    public void initData() {
        initGetIntent();
    }

    private void initGetIntent() {
        //获取预约过来的信息
        String gogpay = getIntent().getStringExtra("GoPay");
        Gson gson = new Gson();
        yuyYue_info = gson.fromJson(gogpay, YuyYueXinxiInfo.class);
        Logger.e("预约信息"+yuyYue_info.toString());
        if (yuyYue_info != null) {
            askPrice.setText(yuyYue_info.getAsk_price() + "元");
            int doctorclinic = yuyYue_info.getDoctorclinic();
            if (doctorclinic == 1) {
                this.doctorclinic.setVisibility(View.VISIBLE);
            } else {
                this.doctorclinic.setVisibility(View.GONE);
            }
            address.setText(yuyYue_info.getHospital_name());
            departmentName.setText(yuyYue_info.getDepartment_name());
            int grade = yuyYue_info.getGrade(); //医生级别
            if (grade == 1) {
                tvtitle.setText("主任医师 ");
            } else if (grade == 2) {
                tvtitle.setText("主治医师 ");
            } else if (grade == 3) {
                tvtitle.setText("副主任医师 ");
            } else {
                tvtitle.setText("住院医师 ");
            }
//            List<String> title = yuyYue_info.getTitle();
//            StringBuffer sb = new StringBuffer();
//            for (int i = 0; i < title.size(); i++) {
//                sb.append(title.get(i) + " ");
//            }
            String title = yuyYue_info.getTitle();
            strong.setText("医治专长:" + title);

            trueName.setText(yuyYue_info.getTrue_name());
            GlideUtils.load(mActivity, ApiService.BASE_URL + yuyYue_info.getPicture(), picture);

            String data_value = yuyYue_info.getData_value().toString().trim();
            String data_week = yuyYue_info.getData_week();
//            //            //同理也可以转为其它样式的时间格式.例如："yyyy/MM/HomeDepartmentlist_Info HH:mm"
//            SimpleDateFormat sdf = new SimpleDateFormat("yyy年MM月dd日");
//            // 例如：cc_time=1291778220
//            long lcc_time = Long.valueOf(data_value);
//            String re_StrTime = sdf.format(new Date(lcc_time * 1000));
            //            String re_StrTime = TimeUtil.get((int)data_value / 1000);

            String re_StrTime = TimeUtil.getInstance().getTime(Integer.parseInt(data_value), TimeUtil.YYYY_MM_DD_TEXT);
            this.time.setText(re_StrTime + " " + data_week);

            if (yuyYue_info.getData_type().equals("1")) {
                time2.setText("上午8:00-12:00");
            } else if (yuyYue_info.getData_type().equals("2")) {
                time2.setText("中午13:00-18:00");
            } else {
                time2.setText("中午18:00-24:00");

            }
//            //医生排班Id
//            scheduling_id = yuyYue_info.getScheduling_id();
        }

    }

    /**
     * 1.判断是否注册 成功跳转支付页面
     *
     * @param view
     */
    @OnClick({R.id.mReservationinfo_next})
    public void onViewClicked(View view) {
        switch (view.getId()) {

            case R.id.mReservationinfo_next:
                int uid = Hawk.get("uid", 0);
                if (uid == 0) {
                    startAct(LogIn_Activity.class);
                } else {
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("GoPay", yuyYue_info);
                    startAct(Diseasedetails_Activity.class, bundle);
                }
                break;
        }
    }
}
